Repository navigation
Validate return URLs in Blazor samples - #693
Merged
Merged
Conversation
Resolve return URLs against the app's base URI and only redirect to them if they stay within the app. This aligns the OIDC, Entra, standalone WebAssembly Identity and MAUI Blazor Web Identity samples with dotnet/aspnetcore#70796. Fixes #692
This was referenced Nov 24, 2026
Open
Only link back to ReturnUrl when it resolves to a URI within the app, so the Return link can't point to another site or run a javascript: URL. Contributes to #692
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the authentication and navigation return-URL validation changes.
No open issues 🎉
What changed in this PR
This PR addresses #692 by validating return URLs across Blazor authentication and navigation samples, preventing external redirects and script URLs while preserving navigation within the app.
Changes:
- Validate OIDC and Entra login/logout destinations against the request’s app base URI, including
PathBase, with an app-root fallback. - Restrict standalone WebAssembly login navigation and MAUI web Identity redirects to destinations within the app.
- Validate
PetDetailreturn links and fall back to the app root for invalid destinations.
| File | Description |
|---|---|
9.0/MauiBlazorWebIdentity/MauiBlazorWeb/MauiBlazorWeb.Web/Components/Account/IdentityRedirectManager.cs |
Validate Identity redirects with an app-root fallback. |
9.0/BlazorWebAssemblyStandaloneWithIdentity/BlazorWasmAuth/Components/Identity/Login.razor |
Restrict post-login navigation to the app. |
9.0/BlazorWebAppOidcBffServer/BlazorWebAppOidcServer/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
9.0/BlazorWebAppOidcBffAutoYarpAspire/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
9.0/BlazorWebAppOidcBffAuto/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
9.0/BlazorWebAppEntraBffYarpAspire/BlazorWebAppEntra/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate Entra return URLs using PathBase. |
9.0/BlazorWebAppEntraBff/BlazorWebAppEntra/LoginLogoutEndpointRouteBuilderExtensions.cs |
Replace path extraction with app-boundary validation. |
9.0/BlazorSample_WebAssembly/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
9.0/BlazorSample_BlazorWebApp/Components/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
8.0/BlazorWebAssemblyStandaloneWithIdentity/BlazorWasmAuth/Components/Identity/Login.razor |
Restrict post-login navigation to the app. |
8.0/BlazorWebAppOidcServer/BlazorWebAppOidcServer/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
8.0/BlazorWebAppOidcBff/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
8.0/BlazorWebAppOidc/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
8.0/BlazorSample_WebAssembly/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
8.0/BlazorSample_BlazorWebApp/Components/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
7.0/BlazorSample_WebAssembly/Pages/templated-components/PetDetail.razor |
Validate return links with an app-root fallback. |
7.0/BlazorSample_Server/Pages/templated-components/PetDetail.razor |
Validate return links with an app-root fallback. |
10.0/MauiBlazorWebIdentity/MauiBlazorWeb.Web/Components/Account/IdentityRedirectManager.cs |
Validate Identity redirects with an app-root fallback. |
10.0/BlazorWebAssemblyStandaloneWithIdentity/BlazorWasmAuth/Pages/Identity/Login.razor |
Restrict post-login navigation to the app. |
10.0/BlazorWebAppOidcBffServer/BlazorWebAppOidcServer/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
10.0/BlazorWebAppOidcBffAutoYarpAspire/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
10.0/BlazorWebAppOidcBffAuto/BlazorWebAppOidc/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate authentication return URLs using PathBase. |
10.0/BlazorWebAppEntraBffYarpAspire/BlazorWebAppEntra/LoginLogoutEndpointRouteBuilderExtensions.cs |
Validate Entra return URLs using PathBase. |
10.0/BlazorWebAppEntraBff/BlazorWebAppEntra/LoginLogoutEndpointRouteBuilderExtensions.cs |
Replace path extraction with app-boundary validation. |
10.0/BlazorSample_BlazorWebAssembly/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
10.0/BlazorSample_BlazorWebApp/Components/Pages/PetDetail.razor |
Validate return links with an app-root fallback. |
Review effort: Balanced
guardrex
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several samples use a return URL from the query string or a form without checking that it points back to the app. A crafted link can send users to another site. In the standalone WebAssembly Identity sample and the general Blazor samples, a
javascript:return URL also runs script on the app's origin.All of them now resolve the return URL against the app's base URI and only use it if the result stays within the app. The code matches the recommended code merged in dotnet/aspnetcore#70796.
Changes:
LoginLogoutEndpointRouteBuilderExtensions.cs, 8.0 to 10.0):/loginand/logoutreduced absolute return URLs to theirPathAndQuery, sohttps://host//evil.examplebecame//evil.example. They now validate the return URL and fall back to the app root. The base URI is built from the request, includingPathBase, which also resolves the existing TODO.BlazorWebAssemblyStandaloneWithIdentity(Login.razor, 8.0 to 10.0):ReturnUrlwas passed directly toNavigationManager.NavigateTo. It now only navigates to URLs within the app.MauiBlazorWebIdentity(IdentityRedirectManager.cs, 9.0 and 10.0): the URI was only checked for being well formed. It now uses the template's check.PetDetail.razor, 7.0 to 10.0):ReturnUrlwas rendered directly as the "Return" link. The link now points toReturnUrlonly if it's within the app, and to the app root otherwise.Validation: all changed projects build. The standalone WebAssembly Identity sample (8.0 to 10.0) and the 10.0
PetDetailpage (Web App and WebAssembly) were tested in Chrome.javascript:and external return URLs no longer run or redirect, and in-app return URLs still work. The OIDC and Entra samples weren't run end to end because they need a real identity provider.Fixes #692